<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function ajax1() {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve("data-111")
                    //reject("err-111") //执行reject后会直接进入catch，没有catch就会报错
                }, 1000)
            })
        }
        function ajax2() {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve("data-222")
                }, 1000)
            })
        }
        async function test() {
            //await后面可以接非promise对象或promise对象
            //let res = await "twj"
            let res1 = await ajax1()
            //会等待resolve()执行完才继续执行，如果是reject()则不会执行下面的代码，直接抛出异常或进入catch
            console.log(res1)
            let res2 = await ajax2(res1)
            console.log(res2)
            return res2
        }
        test().then(res => {
            console.log(res, 1)
            //渲染页面
        }).catch(err => {
            console.log("err", err)
            //处理错误
        })
    </script>
</body>

</html>